package com.wxlalt.rediscache.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wxlalt.rediscache.config.VersionCall;
import com.wxlalt.rediscache.entity.Result;
import com.wxlalt.rediscache.entity.Shop;
import com.wxlalt.rediscache.mapper.ShopMapper;
import com.wxlalt.rediscache.service.IShopService;
import lombok.SneakyThrows;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * @author a1615
 */
@Service
@VersionCall.Version("v1")
public class ShopServiceImpl_v1 extends ServiceImpl<ShopMapper, Shop> implements IShopService {



    @SneakyThrows
    @Override
    public Result queryById(Long id) {
        Thread.sleep(1000);
        Shop shop = getById(id);
        return null == shop
                ?Result.fail("店铺不存在")
                :Result.ok(shop);
    }

    @Override
    @Transactional
    public Result update(Shop shop) {
        //先更新数据库再删除缓存
        Long id = shop.getId();
        if (id == null) {
            return Result.fail("店铺id不能为空");
        }
        // 1.更新数据库
        updateById(shop);
        return Result.ok();

    }


}
